<html>
<head><meta charset="utf-8"><title>pr #67911 - duplicate closure regions · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html">pr #67911 - duplicate closure regions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="185040425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040425">(Jan 07 2020 at 18:44)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> let me know when you're available to talk about PR <a href="https://github.com/rust-lang/rust/pull/67911" target="_blank" title="https://github.com/rust-lang/rust/pull/67911">https://github.com/rust-lang/rust/pull/67911</a></p>



<a name="185040536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040536">(Jan 07 2020 at 18:45)</a>:</h4>
<p><span class="user-mention" data-user-id="125294">@Aaron Hill</span> ok, I can't prob chat too much now, but one immediate question I had was whether we believe this to be primarily a matter of <em>diagnostics</em>? I guess I have to re-read your original description. Is it the case that the error (with your PR) is processed and reported in the closuer's owner, rather than within the closure?</p>



<a name="185040620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040620">(Jan 07 2020 at 18:46)</a>:</h4>
<p>I believe it's reported within the closure itself</p>



<a name="185040637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040637">(Jan 07 2020 at 18:46)</a>:</h4>
<p>before and after?</p>



<a name="185040648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040648">(Jan 07 2020 at 18:46)</a>:</h4>
<p>yes</p>



<a name="185040677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040677">(Jan 07 2020 at 18:46)</a>:</h4>
<p>The current diagnostic isn't "wrong", exactly - it's just suboptimal, since the computed upper bound is overly conservative</p>



<a name="185040708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040708">(Jan 07 2020 at 18:47)</a>:</h4>
<p>Specifically, the code gives up trying to find an upper bound, since it doesn't know that some of the regions involved are actually "the same"</p>



<a name="185040739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040739">(Jan 07 2020 at 18:47)</a>:</h4>
<p>Regarding your comment on the PR - I'm not sure that I understand how erasing regions affects this</p>



<a name="185040829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185040829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185040829">(Jan 07 2020 at 18:48)</a>:</h4>
<p>If we were to erase regions earlier, wouldn't we still need to somehow remember which regions are actually the same?</p>



<a name="185041025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041025">(Jan 07 2020 at 18:50)</a>:</h4>
<p>e.g. code like <code>fn bar&lt;'a&gt;(first: &amp;'a u8, second: &amp;'a u8) { || do_something(first, second); }</code> needs to know that 'first' and 'second' have the same region</p>



<a name="185041336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041336">(Jan 07 2020 at 18:52)</a>:</h4>
<p>To answer your earlier question - yes, I believe this is entirely a matter of diagnostics. The current  non-diagnostic code seems perfectly correct - however, the information we need ('more precise' knowledge of region relationships) is not available while we're checking the closure. Changing the diagnostic code seemed to be the simplest way of resolving this</p>



<a name="185041750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041750">(Jan 07 2020 at 18:56)</a>:</h4>
<blockquote>
<p>e.g. code like <code>fn bar&lt;'a&gt;(first: &amp;'a u8, second: &amp;'a u8) { || do_something(first, second); }</code> needs to know that 'first' and 'second' have the same region</p>
</blockquote>
<p>it doesn't know that now, right?</p>



<a name="185041776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041776">(Jan 07 2020 at 18:56)</a>:</h4>
<p>Ideally, it would not know that</p>



<a name="185041787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041787">(Jan 07 2020 at 18:56)</a>:</h4>
<p>By "it" here, I specifically mean the closure</p>



<a name="185041805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041805">(Jan 07 2020 at 18:57)</a>:</h4>
<p>the closure doesn't know now</p>



<a name="185041809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041809">(Jan 07 2020 at 18:57)</a>:</h4>
<p>The outer fn item <em>does</em> remember those details (i.e., the things that were hand-written by the user)</p>



<a name="185041819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041819">(Jan 07 2020 at 18:57)</a>:</h4>
<p>right</p>



<a name="185041837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041837">(Jan 07 2020 at 18:57)</a>:</h4>
<p>the closure would communicate back that they must be equal (if that is required locally)</p>



<a name="185041846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041846">(Jan 07 2020 at 18:57)</a>:</h4>
<p>and then the outer fn item would determine if that can be made to be true</p>



<a name="185041854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041854">(Jan 07 2020 at 18:57)</a>:</h4>
<p>that's the intended design, at least</p>



<a name="185041875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041875">(Jan 07 2020 at 18:57)</a>:</h4>
<p>in part because it's not easy to tell if they are equal -- we don't know at the point where we are building MIR, or we won't know</p>



<a name="185041939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041939">(Jan 07 2020 at 18:58)</a>:</h4>
<p>because of subtyping etc</p>



<a name="185041950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041950">(Jan 07 2020 at 18:58)</a>:</h4>
<p>consider e.g.</p>



<a name="185041972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185041972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185041972">(Jan 07 2020 at 18:58)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">x</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">y1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">y</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="o">||</span><span class="w"> </span><span class="p">...(</span><span class="n">x1</span><span class="p">,</span><span class="w"> </span><span class="n">y1</span><span class="p">)...</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="185042029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042029">(Jan 07 2020 at 18:59)</a>:</h4>
<p>here, the type of the captured value needs to be inferred</p>



<a name="185042045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042045">(Jan 07 2020 at 18:59)</a>:</h4>
<p>(but we don't want to be doing that inference until borrowck/polonius etc)</p>



<a name="185042072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042072">(Jan 07 2020 at 18:59)</a>:</h4>
<p>anyway I have to go and understand how it is that your PR improves diagnostics specifically I guess</p>



<a name="185042295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042295">(Jan 07 2020 at 19:01)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span>: See here: <a href="https://github.com/rust-lang/rust/blob/56446fef49d73212f63ea7aa0680d5d602f19b9a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs#L332" target="_blank" title="https://github.com/rust-lang/rust/blob/56446fef49d73212f63ea7aa0680d5d602f19b9a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs#L332">https://github.com/rust-lang/rust/blob/56446fef49d73212f63ea7aa0680d5d602f19b9a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs#L332</a></p>



<a name="185042332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042332">(Jan 07 2020 at 19:01)</a>:</h4>
<p>Being able to compute a correct upper bound allows this branch to succeed</p>



<a name="185042386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042386">(Jan 07 2020 at 19:01)</a>:</h4>
<p>which allows us to create a <code>BorrowExplanation::MustBeValidFor</code> instead of a <code>BorrowExplanation::Unexplained</code></p>



<a name="185042471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042471">(Jan 07 2020 at 19:02)</a>:</h4>
<p>the <code>BorrowExplanation</code> gets checked later on when producing the message, and allows us to emit a more specific diagnostic</p>



<a name="185042521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042521">(Jan 07 2020 at 19:02)</a>:</h4>
<p>w.r.t erasing regions - if type check were to erase the regions, where would the original relationships between the regions be stored?</p>



<a name="185042565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185042565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185042565">(Jan 07 2020 at 19:03)</a>:</h4>
<p>Would the closure parent still have the information needed to check the propagated constraints, or would that be done elsewhere?</p>



<a name="185625241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185625241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185625241">(Jan 14 2020 at 18:37)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> let me know when you're available to talk more about this</p>



<a name="185625346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185625346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185625346">(Jan 14 2020 at 18:38)</a>:</h4>
<p>Is there a branch somewhere that contains code for erasing regions during typecheck? Or a description somewhere of what those changes will look like?</p>



<a name="185625598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185625598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185625598">(Jan 14 2020 at 18:41)</a>:</h4>
<p>If I understand correctly, typecheck will erase the regions (so <code>Closure { upvar_a: Foo&lt;'a&gt;, upvar_b: Bar&lt;'b&gt; }</code> becomes <code>Closure { upvar_a: Foo&lt;'erased&gt;, upvar_b: Bar&lt;'erased&gt;</code>. Then, borrowcheck will create fresh inference variables: <code>Closure { upvar_a: Foo&lt;_#1r&gt;, upvar_b: Bar&lt;_#2r&gt;</code></p>



<a name="185625812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185625812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185625812">(Jan 14 2020 at 18:42)</a>:</h4>
<p>If that's the case, I think we could still propagate the necessary information for diagnostics. When we erase regions, we could mark which 'positions' (given by the order in which the regions are visited) correspond to the same region</p>



<a name="185625911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185625911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185625911">(Jan 14 2020 at 18:43)</a>:</h4>
<p>e.g. for <code>Closure { first: Foo&lt;'a&gt;, second: Bar&lt;'a&gt;, third: Foo&lt;'b&gt; }</code> we would record something like <code>identical_regions: [ {0, 1}, {2} ]</code></p>



<a name="185625988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185625988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185625988">(Jan 14 2020 at 18:44)</a>:</h4>
<p>During borrowcheck, we would associate this information with the freshly created region variables</p>



<a name="185626198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185626198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185626198">(Jan 14 2020 at 18:46)</a>:</h4>
<p>The only other solution I can think of would be to use the context of the parent item when running the diagnostic code for closure errors. That would give us access to the 'identical' region information - however, I think we would also lose all information about 'interior' regions in the closure</p>



<a name="185626264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185626264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185626264">(Jan 14 2020 at 18:47)</a>:</h4>
<p>The borrowcheck region error code seems quite complicated, so I think it would require a large amount of effort to prevent any diagnostic regressions</p>



<a name="185632075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/pr%20%2367911%20-%20duplicate%20closure%20regions/near/185632075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/pr.20.2367911.20-.20duplicate.20closure.20regions.html#185632075">(Jan 14 2020 at 19:40)</a>:</h4>
<blockquote>
<p>Is there a branch somewhere that contains code for erasing regions during typecheck? Or a description somewhere of what those changes will look like?</p>
</blockquote>
<p>IIUC one of the first steps is <a href="https://github.com/rust-lang/rust/pull/67681" target="_blank" title="https://github.com/rust-lang/rust/pull/67681">https://github.com/rust-lang/rust/pull/67681</a>, and the plan is currently being worked on</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>